﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TDAPIOLELib;

namespace QCCure.Core
{
    [Serializable]
    public class QCBugField
    {
        private string name;
        private string value;

        public QCBugField()
        {
        }

        public QCBugField(string name)
        {
            this.name = name;
        }

        public QCBugField(TDField field)
        {
            this.name = field.Name;
        }

        public string Name
        {
            get {
                if (name != null)
                {
                    return (name.StartsWith("BG_") ? name.Substring(3) : name);
                }
                else
                {
                    return "";
                }
            }
        }

        public string QCName
        {
            get { return name; }
            set { name = value; }
        }

        public string Value
        {
            get { return value; }
            set { this.value = value; }
        }

        // override object.Equals
        public override bool Equals(object obj)
        {

            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            QCBugField other = obj as QCBugField;

            return StringComparer.CurrentCulture.Equals(name, other.name) &&
                   StringComparer.CurrentCulture.Equals(value, other.value);
        }

        // override object.GetHashCode
        public override int GetHashCode()
        {
            int nameHashCode = name != null ? name.GetHashCode() : 0;
            int valueHashCode = value != null ? value.GetHashCode() : 0;
            return nameHashCode ^ ((int)valueHashCode >> 32);
        }


        public override string ToString()
        {
            return Name;
        }
    }
}
